<?php
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/cms.php';
include_once '../../model/email.php';
include_once '../../model/contactus.php';
require_once '../../model/sitesettings.php';
require_once '../../model/admindetails.php';

## Create Objects
/*******************************/
$cmsObj   	= new Model_CMS();
$emailObj 	= new  Model_Email();
$contactObj = new  Model_Contactus();
$setingsObj = new Model_Sitesettings();
$adminObj 	= new Model_AdminDetails();
/*******************************/
$submenu_id = 6;
$cmsArray = $cmsObj->getSubmenuDetailsById($submenu_id);
$smarty->assign("submenu_content", $cmsArray['submenu_content']);	
$smarty->assign("submenu_title", $cmsArray['submenu_title']);	
//echo "<pre>";print_r($cmsArray['submenu_content']);

$seoArray = $cmsObj->getDetailsSeoById(5);
$smarty->assign("seoArray",$seoArray);
	

if($_POST['Submit']!='')
{
	//echo "<pre>";print_r($_POST);exit;
	if(trim($_POST['first_name'])!='' && trim($_POST['email']) !='' && trim($_POST['phone']!='' && trim($_POST['comment'])!=''))	
	{
					$contactArray =	array();
					extract($_POST);
					$contactArray['name'] 				= $first_name.' '.$last_name;
					$contactArray['email_id'] 			= $email;
					$contactArray['subject'] 		    = $subject;	
					$contactArray['phone'] 		    	= $phone;	
					$contactArray['description']		= $comment;	
					$contactArray['readflag'] 			= 'unread';
					$contactArray['entry_on'] 			= getCurDate();	
					$result  = 	$contactObj->addContactus($contactArray);
					
					$email_message 		= $emailObj->getEmailById(5);	
					$e_subject 			= $email_message['email_subject'];
					$message 			= $email_message['email_content'];	
										
					$subject 			= str_replace('[[NAME]]', ucwords($first_name.' '.$last_name), $e_subject);		
						
					$message 			= str_replace('[[NAME]]',ucwords($first_name.' '.$last_name) , $message);
					$message 			= str_replace('[[CONTACTNO]]',$phone, $message);
					$message 			= str_replace('[[EMAIL]]',$email, $message);
					$message 			= str_replace('[[COMMENT]]',$comment, $message);
					$message 			= str_replace('[[SITENAME]]',SITE_URL, $message);
				
					$emailTemplate 		= file_get_contents('../../emailtemplate.html');
					$template_msg 		= str_replace('[SITENAME]',SITENAME , $emailTemplate);
					$template_msg 		= str_replace('[LOGO]','<img src="'.SITE_URL.'/uploads/logo/'.$imageDetails.'">',$template_msg);
					$template_msg 		= str_replace('[MESSAGE]',$message,$template_msg); 
						
					$adminEmail 		= $adminObj->getAdminEmailValue();
					$to 				= $adminEmail;
					$from 				= $email;
					$fromname 			= TITLE;	
					
					//echo $to;echo"<br>";echo $template_msg;echo"<br>";echo $subject;echo"<br>";echo $from;echo"<br>";echo $fromname;echo"<br>";exit;
					if($to!='')
					@send_mail($to, $template_msg, $subject, $from, $fromname);
										
					//$_SESSION['msg'] = "<span class='success_msg'>Thank you for contacting Getbids.hopto.org <br/>We will follow up with you shortly.</span>";
					$_SESSION['msg'] = "<div class='success_msg'><span>Your feedback has been sent successfully !.</span></div>";
					header('location:'.SITE_URL.'/cms/contactus');
					exit;
	}
}
$setingsInfo=$setingsObj->getSiteSetting();
$smarty->assign('setingsInfo', $setingsInfo);
//echo "<pre>";print_r($setingsInfo);exit;

if($_SESSION['msg']!=''){
	$smarty->assign("successMsg", $_SESSION['msg']);
	unset($_SESSION['msg']);
}
unset($emailObj);
unset($cmsObj);
//Active Class
$active = 'contactus';
$smarty->assign('active', $active);
$smarty->display(TEMPLATEDIR . '/modules/cms/contactus.tpl');

unset($cmsObj);
unset($smarty);
?>